<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <section>
    <div>
      <label for="">添加：
        <input type="text" class="input">
      </label>
    </div>
    <ul class="uls">
    </ul>
  </section>

  <script>
    ; (function () {
      let input = document.querySelector('.input');
      let ul = document.querySelector('.uls');
      input.addEventListener('keydown', function (e) {
        if (e.keyCode === 13) {
          let val = this.value.trim();
          if (val) {
            let lis = document.createElement('li');
            lis.innerHTML = val;
            ul.appendChild(lis);
            this.value = '';
          }
        }
      }, false);
      ul.addEventListener('click', function(e) {
        let tag = e.target;
        if (tag.tagName === 'LI') {
          alert(tag.innerHTML);
        }
        e.stopPropagation();

      }, false);
    })();
  </script>
</body>

</html>